package com.ruoyi.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.business.service.IGwLocationService;
import com.ruoyi.common.core.domain.entity.GwLocation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 取号位置Controller
 *
 * @author ruoyi
 * @date 2024-07-24
 */
@RestController
@RequestMapping("/gwLocation")
public class GwLocationController extends BaseController
{
    @Autowired
    private IGwLocationService gwLocationService;

    /**
     * 查询取号位置列表
     */
    //@PreAuthorize("@ss.hasPermi('com/ruoyi/business:location:list')")
    @GetMapping("/list")
    public TableDataInfo list(GwLocation gwLocation)
    {
        startPage();
        List<GwLocation> list = gwLocationService.selectGwLocationList(gwLocation);
        return getDataTable(list);
    }
    @GetMapping("/gwLocation")
    public AjaxResult gwLocation()
    {
        GwLocation gwLocation = new GwLocation();
        List<GwLocation> list = gwLocationService.selectGwLocationList(gwLocation);
        if (list.size()!=0) {
            gwLocation = list.get( 0 );
        }
        return AjaxResult.success(gwLocation);
    }


    /**
     * 导出取号位置列表
     */
    //@PreAuthorize("@ss.hasPermi('com/ruoyi/business:location:export')")
    @Log(title = "取号位置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GwLocation gwLocation)
    {
        List<GwLocation> list = gwLocationService.selectGwLocationList(gwLocation);
        ExcelUtil<GwLocation> util = new ExcelUtil<GwLocation>(GwLocation.class);
        util.exportExcel(response, list, "取号位置数据");
    }

    /**
     * 获取取号位置详细信息
     */
    //@PreAuthorize("@ss.hasPermi('com/ruoyi/business:location:query')")
    @GetMapping(value = "/{locationId}")
    public AjaxResult getInfo(@PathVariable("locationId") Long locationId)
    {
        return success(gwLocationService.selectGwLocationByLocationId(locationId));
    }

    /**
     * 新增取号位置
     */
    //@PreAuthorize("@ss.hasPermi('com/ruoyi/business:location:add')")
    @Log(title = "取号位置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GwLocation gwLocation)
    {
        return toAjax(gwLocationService.insertGwLocation(gwLocation));
    }

    /**
     * 修改取号位置
     */
    //@PreAuthorize("@ss.hasPermi('com/ruoyi/business:location:edit')")
    @Log(title = "取号位置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GwLocation gwLocation)
    {
        return toAjax(gwLocationService.updateGwLocation(gwLocation));
    }

    /**
     * 删除取号位置
     */
    //@PreAuthorize("@ss.hasPermi('com/ruoyi/business:location:remove')")
    @Log(title = "取号位置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{locationIds}")
    public AjaxResult remove(@PathVariable Long[] locationIds)
    {
        return toAjax(gwLocationService.deleteGwLocationByLocationIds(locationIds));
    }
}
